package com.xxxx.blog.service.serviceImpl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xxxx.blog.entity.User;
import com.xxxx.blog.mapper.UserMapper;
import com.xxxx.blog.service.UserService;
import com.xxxx.blog.utils.Maps;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper,User> implements UserService {

    @Resource
    private UserMapper userMapper;


    @Override
    public int create(User user) {
        return userMapper.create(user);
    }

    @Override
    public int delete(Integer id){
        return userMapper.delete(Maps.build(id).getMap());
    }

    public int update(User user){
        return userMapper.update(Maps.build(user.getId()).beanToMapForUpdate(user));
    }

    public PageInfo<User> query(User user){
        if(user != null && user.getPage() != null){
            PageHelper.startPage(user.getPage(),user.getLimit());
        }
        List<User> list = userMapper.query(Maps.build().beanToMap(user));
        return new PageInfo<User>(list);
    }

    public User detail(Integer id){
        return userMapper.detail(Maps.build(id).getMap());
    }

    public User login(String userName,String password){
        return userMapper.detail(Maps.build()
                .put("userName",userName)
                .put("password",password)
                .getMap());
    }

    public int count(User user){
        return userMapper.count(Maps.build().beanToMap(user));
    }
}

